package com.wandian.ui.controls
{
	import flash.display.*;
	
	public class ContentController extends MovieClip
	{
		private var fContent_mc:MovieClip;
		private var fContentY_num:Number;
		private var fContentX_num:Number;
		private var fContentName_str:String;
		
		public function ContentController(param1:String = "", param2:Number = 0, param3:Number = 0, param4:Boolean = false)
		{
			this.contentX = param2;
			this.contentY = param3;
			if (param1)
			{
				this.contentToUseName = param1;
			}
			else if (param4)
			{
				this.tryToUsePlaceholderAsContent();
			}
			return;
		}// end function
		
		public function set contentY(param1:Number) : void
		{
			this.fContentY_num = param1;
			this.updateContentPosition();
			return;
		}// end function
		
		public function set contentX(param1:Number) : void
		{
			this.fContentX_num = param1;
			this.updateContentPosition();
			return;
		}// end function
		
		public function get contentY() : Number
		{
			return this.fContentY_num;
		}// end function
		
		protected function set contentToUse(param1:MovieClip) : void
		{
			this.detachContent();
			this.fContent_mc = param1;
			this.updateContentPosition();
			this.removePlaceholderIfRequired();
			this.addChild(this.content);
			return;
		}// end function
		
		protected function detachContent() : void
		{
			if (this.content)
			{
				this.removeChild(this.content);
			}
			return;
		}// end function
		
		public function set contentToUseName(param1:String) : void
		{
			this.fContentName_str = param1;
			this.contentToUse = AssetsLibrary.getInstance().newMovieClip(this.contentName);
			return;
		}// end function
		
		protected function tryToUsePlaceholderAsContent() : void
		{
			if (this.placeholder)
			{
				this.contentToUse = this.placeholder;
			}
			return;
		}// end function
		
		public function get content() : MovieClip
		{
			return this.fContent_mc;
		}// end function
		
		protected function get placeholder() : MovieClip
		{
			try
			{
				return this["placeholder_mc"];
			}
			catch (aError_err:Error)
			{
			}
			return null;
		}// end function
		
		protected function removePlaceholderIfRequired() : void
		{
			if (this.placeholder && this.placeholder != this.content)
			{
				try
				{
					this.removeChild(this.placeholder);
				}
				catch (aError_err:Error)
				{
				}
			}
			return;
		}// end function
		
		public function get contentName() : String
		{
			return this.fContentName_str;
		}// end function
		
		protected function updateContentPosition() : void
		{
			if (this.content)
			{
				this.content.x = this.contentX;
				this.content.y = this.contentY;
			}
			return;
		}// end function
		
		public function get contentX() : Number
		{
			return this.fContentX_num;
		}// end function
		
	}
}
